<?php require_once('../../Connections/cotiza.php'); ?>
<?php
$campo   = $_GET['campo'];
$acc     = $_GET['acc'];
$label   = $_GET['label'];
$cliente = $_GET['cliente'];
$tipo    = $_GET['tipo'];

mysql_select_db($database_cotiza, $cotiza);

if($acc == "search")
{
	$b = $_POST['busqueda'];
	$query = "SELECT * FROM terminados_view WHERE solic_cliente = '$cliente' AND (solic_codigo like '%$b%' or solic_npcliente like '%$b%' OR solic_sku like '%$b%') ORDER BY solic_npcliente";
}
else
	$query = "SELECT * FROM terminados_view WHERE solic_cliente = '$cliente' ORDER BY solic_npcliente";

$busqueda = mysql_query($query, $cotiza) or die(mysql_error());
$row = mysql_fetch_assoc($busqueda);
$totalRows = mysql_num_rows($busqueda);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>..:: Materia prima ::..</title>
<link href="../../main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.default_title {
	color: #FFF;
}
-->
</style>
</head>

<body onload="document.form1.busqueda.focus();">
<form id="form1" name="form1" method="post" action="articulos.php?tipo=<?php echo $tipo;?>&campo=<?php echo $campo; ?>&acc=search&cliente=<?php echo $cliente;?>">
  <table border="0" align="center">
    <tr>
      <td width="128">B&uacute;squeda de Mat. prima:</td>
      <td width="111"><input name="busqueda" class="default" size="20" autocomplete="off" value="<?php echo $b;?>" /></td>
      <td width="54"><input type="submit" value="Buscar" class="v8" /></td>
    </tr>
  </table>
</form>
<br />
<?php if($totalRows >0){?>
  <table border="1" align="center" cellpadding="2" cellspacing="0">
    <tr class="default_title">
      <td width="109" align="center" bgcolor="#0000CC">Id Art&iacute;culo</td>
      <td width="255" align="center" bgcolor="#0000CC">Descripci&oacute;n</td>
      <td width="100" align="center" bgcolor="#0000CC">SKU</td>
      <td width="81" align="center" bgcolor="#0000CC">Ultima OV</td>
      <td width="72" align="center" bgcolor="#0000CC">F. vencimiento</td>
      <td width="72" align="center" bgcolor="#0000CC">Vigencia</td>
    </tr>
    <?php do { 
			
				$f  = split("-",$row['solic_fecha_ov']);
				$fv = split("-",$row['solic_p_vencido']);
				
				$fv2 = $fv[0].$fv[1].$fv[2];
				$fa  = date('Ymd');
				
				if($fv2 < $fa)
					$vencido = 1;
				else
					$vencido = 0;
	?>
    <tr>
      <td width="109"><a href="javascript:window.opener.document.getElementById('<?php echo $campo; ?>').value='<?php echo $row['solic_codigo']; ?>';window.opener.document.getElementById('<?php echo $tipo; ?>').value='<?php echo $row['solic_id']; ?>';<?php $d = $row['pt_desc']; if($label <> "") echo "window.opener.document.getElementById('$label').innerHTML='$d';"; ?><?php if($vencido == 1) echo "window.opener.document.getElementById('vencido').value='1';"; ?>window.opener.document.getElementById('<?php echo $campo; ?>').focus();window.close();"> <?php echo $row['solic_codigo']; ?> </a>&nbsp;</td>
      <td width="255"><?php echo $row['solic_npcliente'];?>&nbsp;</td>
      <td width="100"><?php echo $row['solic_sku'];?>&nbsp;</td>
      <td width="81" align="right"><?php echo $f[2]."/".$f[1]."/".$f[0];?>&nbsp;</td>
      <td width="72" align="right"><?php echo $fv[2]."/".$fv[1]."/".$fv[0];?>&nbsp;</td>
      <td width="72" align="right"><?php if($vencido)echo "Vigente"; else echo "Vencido";?>&nbsp;</td>
    </tr>
      <?php } while ($row = mysql_fetch_assoc($busqueda)); ?>
  </table>
<?php }?>
<?php if($totalRows == 0){?>
<table width="321" border="0" align="center">
  <tr>
    <td width="315" align="center"><strong>No existen Art&iacute;culos</strong></td>
  </tr>
</table>
<?php }?>
</body>
</html>
<?php 
mysql_close($cotiza);
?>